{extend name='admin@main'}

{block name="content"}

{include file='store@goods/form_style'}
{php}
{//var_dump($vo);}
{/php}
<form onsubmit="return false;" id="GoodsForm" data-auto="true" method="post" class='layui-form layui-card' autocomplete="off">

    <div class="layui-card-body think-box-shadow padding-left-40">

        <div class="layui-form-item layui-row layui-col-space15">

            <label class="layui-col-xs9 relative">
                <span class="color-green">商品名称</span>
                <input name="title" required class="layui-input" placeholder="请输入商品名称" value="{$vo.title|default=''}">
            </label>
        </div>

        <div class="layui-form-item">
            <span class="color-green label-required-prev">商品规格及商品信息<span class="color-red font-s12">（规格填写后不允许再次修改）</span></span>

            <table class="layui-table margin-top-10">
                <thead>
                <tr>
                    <th width="10%" ng-repeat="x in specsTreeNava track by $index" class="nowrap" ng-bind="x">信息</th>

                    <th width="10%" class="text-center nowrap">套餐价格 <a class="layui-icon">&#xe63c;</a></th>
                    <!-- <th width="10%" class="text-center nowrap">限制接待人数 <a class="layui-icon">&#xe63c;</a></th> -->
                    <th width="10%" class="text-center nowrap">套餐积分 <a class="layui-icon">&#xe63c;</a></th>
                    <th width="10%" class="text-center nowrap">套餐期限 <a class="layui-icon">&#xe63c;</a></th>
                    <th width="10%" class="text-center nowrap">套餐类型 <a class="layui-icon">&#xe63c;</a></th>
                    <th width="10%" class="text-center nowrap">销售状态</th>
                </tr>

                <tr>
                    <th width="10%" class="text-center nowrap">                        

                        <input name="money" value="{$vo.money|default='-'}" class="layui-input border-0 padding-left-0 text-center" >

                    </th>
<!--                     <th width="10%" class="text-center nowrap">
                    <input name="outAppnumber" value="{$vo.outAppnumber|default=''}" max="100" min="0" lay-ignore type="number">
                    </th> -->
                    <th width="10%" class="text-center nowrap">
                    <input name="frequency" value="{$vo.frequency|default=''}" max="100" min="0" lay-ignore type="number">
                    </th>
                    <th width="10%" class="text-center nowrap"> 


                        <label class="padding-0 margin-10 member-type-year" style="display:block">
                            {if @$vo.year!=0}
                            <input name="year" value="{$vo.year|default=''}" max="12" min="0" lay-ignore type="number">年/付套餐
                            <input name="type_check" value="year" checked lay-ignore type="radio"></br>
                            {else}
                            <input name="year" max="12" min="0" lay-ignore type="number">年/付套餐<input  name="type_check" value="year" lay-ignore type="radio"></br>
                            {/if}
                            </label>
                       
                             <label class="padding-0 margin-10 member-type-month" style="display:block">
                            {if @$vo.month!=0}
                            <input name="month" value="{$vo.month|default=''}" max="12" min="0" lay-ignore type="number">月/付套餐<input name="type_check" value="month" checked lay-ignore type="radio"></br>
                            {else}
                                <input name="month" max="12" min="0" lay-ignore type="number">月/付套餐<input name="type_check" value="month" lay-ignore type="radio"></br>
                            {/if}
                            </label>
                       
                             <label class="padding-0 margin-10 member-type-day" style="display:block">
                            {if @$vo.day!=0}
                            <input name="day" value="{$vo.day|default=''}" max="365" min="0" lay-ignore type="number">日/付套餐<input name="type_check" value="day" checked lay-ignore type="radio"></br>
                            {else}
                                <input name="day" max="365" min="0" lay-ignore type="number">日/付套餐<input name="type_check" value="day" lay-ignore type="radio"></br>
                            {/if}
                        </label>

                    </th>
                  <th width="10%" class="text-center nowrap">

                         <label class="think-checkbox margin-0 full-width full-height block">
                        {if @$vo.type}
                         {switch name="vo.type" }
                           
                            {case value='1'}
                                    个人套餐<input  name="commodity_type" value="1" checked lay-ignore type="radio">
                                    </br>
                                    </br>
                                    企业套餐<input  name="commodity_type" value="2"  lay-ignore type="radio">
                            {/case}

                            {case value='2'}
                                   个人套餐<input  name="commodity_type" value="1"  lay-ignore type="radio">
                                   </br>
                                   </br>
                                   企业套餐<input  name="commodity_type" value="2" checked lay-ignore type="radio">
                            {/case}  
                            {default  /}-
                         {/switch}
                        {else}
                            个人套餐<input name="commodity_type" value="1" checked lay-ignore type="radio">
                            </br>
                            </br>
                            企业套餐<input name="commodity_type" value="2" checked lay-ignore type="radio">
<!--                             </br>
                            物业套餐<input name="commodity_type" value="3" checked lay-ignore type="radio"> -->

                        {/if}


                        </label>

                    </th>

                    <th width="10%" class="text-center nowrap">

                         <label class="think-checkbox margin-0 full-width full-height block">
                            {if @$vo.status==1}
                                <input name="status" lay-ignore type="checkbox" >
                            {else}
                                <input name="status" lay-ignore type="checkbox" checked="checked" >
                            {/if}

                        </label>

                    </th>
                </tr>

                </thead>



            </table>

            <textarea class="layui-textarea layui-hide" name="specs">{{specs}}</textarea>
            <textarea class="layui-textarea layui-hide" name="lists">{{specsTreeData}}</textarea>
        </div>

        <div class="layui-form-item block">
            <span class="label-required-prev color-green">商品详细内容</span>
            <textarea name="remark">{$vo.remark|default=''|raw}</textarea>
        </div>

        <div class="layui-form-item text-center">
            {notempty name='vo.id'}<input type="hidden" name="id" value="{$vo.id}">{/notempty}
            
            <button class="layui-btn" type="submit">保存商品</button>

            <button class="layui-btn layui-btn-danger" data-close  ng-click="hsitoryBack()" type="button">取消编辑</button>
        </div>

    </div>
</form>
{/block}

{block name='script'}
<textarea class="layui-hide" id="goods-specs">{$vo.specs|raw|default=''}</textarea>
<textarea class="layui-hide" id="goods-value">{$defaultValues|raw|default=''}</textarea>
<script>
    window.form.render();
    require(['ckeditor', 'angular'], function () {
        window.createEditor('[name="remark"]', {height: 250});

        /**初始化AG**/
        var app = angular.module("GoodsForm", []).run(callback);
        angular.bootstrap(document.getElementById(app.name), [app.name]);

        $('input[name="type_check"]').change(function(){
              var check_val = $("input[name='type_check']:checked").val();
              console.log(check_val)
              switch(check_val)
                {
                    case 'year':
                        $('input[name="month"').css({'display':'none'})
                        $('input[name="day"').css({'display':'none'})
                        $('input[name="year"').css({'display':'unset'})
                        break;
                    case 'month':
                        $('input[name="month"').css({'display':'unset'})
                        $('input[name="day"').css({'display':'none'})
                        $('input[name="year"').css({'display':'none'})
                        break;
                    case 'day':
                        $('input[name="month"').css({'display':'none'})
                        $('input[name="day"').css({'display':'unset'})
                        $('input[name="year"').css({'display':'none'})
                        break;
                    default:

                }
        })
        function callback($rootScope) {
            // 返回商品列表
            $rootScope.hsitoryBack = function () {
                $.msg.confirm('确定要取消编辑吗？', function (index) {
                    history.back(), $.msg.close(index);
                });
            };
            // 设置默认值
            $rootScope.setValue = function (key, type, value, call) {
                $rootScope.maps[key] || ($rootScope.maps[key] = {});
                return $rootScope.maps[key][type] = eval(call.replace('_', "'" + value + "'"));
            };
            // 读取默认值
            $rootScope.getValue = function (key, callback) {
                if (typeof callback === 'function') {
                    return callback($rootScope.maps[key] || {});
                }
                return {};
            };
            // 去除空白字符
            $rootScope.trimSpace = function (value) {
                return (value + '').replace(/\s*/ig, '');
            };

        }
    })
</script>
{/block}